﻿using Basic.HrRemoteModel.DicItem;
using Basic.HrRemoteModel.DicItem.Model;
using WeDonekRpc.Client.Attr;

namespace Shop.ExtendService.lmpl
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class DictItemService : IDictItemService
    {
        private readonly IDictConfig _Config;
        public DictItemService ( IDictConfig config )
        {
            this._Config = config;
        }

        public DicItem[] Gets ( string key )
        {
            long dictId = this._Config.GetDictId(key);
            if ( dictId == 0 )
            {
                return Array.Empty<DicItem>();
            }
            return new GetDicItems { DicId = dictId }.Send();
        }

        public Dictionary<string, string> GetText ( string key, string[] vals )
        {
            DicItem[] item = this.Gets(key);
            if ( item.Length == 0 )
            {
                return [];
            }
            return item.Where(a => vals.Contains(a.DicValue)).ToDictionary(a => a.DicValue, b => b.DicText);
        }
    }
}
